﻿Ext.define('app.prm.task.edit.Process', {
    extend: 'Ext.grid.Panel',
    taskId: 0,
    tbar: [],
    border: false,
    autoHeight: true,
    viewConfig: {
        forceFit: true
    },
    initComponent: function () {
        var me = this;

        me.store = Ext.create("app.ux.PrmStore", { url: '/api/services/app/gantt/GetProcess?taskId=' + me.taskId });

        me.tbar = ["->", {
            text: '新增一行', icon: '/Content/images/add.png', handler: function () {
                var win = me.getWin();
                win.show();
            }
        }];
        me.callParent();
    },
    columns: [
        {
            header: '进度',
            dataIndex: 'value',
            renderer: function (value, p, record) { return value + "%"; }
        },
        {
            header: '创建人',
            dataIndex: 'createBy'
        },
        {
            header: '创建时间',
            dataIndex: 'createOn'
        },
        {
            header: '备注',
            dataIndex: 'remark'
        }
    ],
    getWin: function () {
        var me = this;
        if (!this.winPanel) {
            this.winPanel = new Ext.Window({
                title: '新增进度',
                modal: true,
                closable: false,
                width: 450,
                height: 300,
                layout: 'fit',
                bodyStyle: 'padding:2px',
                items: [me.getFormPanel()],
                buttons: [
                    { text: '保存', handler: function () { me.saveForm(); } },
                    { text: '关闭', handler: function () { me.closeWin(); } }
                ]
            });
        }
        return this.winPanel;
    },
    closeWin: function () {
        this.getWin().hide();
    },
    saveForm: function () {
        var me = this;
        var forms = me.getFormPanel().getForm().getValues();
        forms.TaskId = me.taskId;
        App.AjaxPost('/api/services/app/gantt/SaveProcess', forms, function (data) {
            me.store.load();
            me.winPanel.close();
        });
    },
    getFormPanel: function () {
        if (!this.formpanel) {
            this.formpanel = new Ext.form.FormPanel({
                labelAlign: 'right',
                labelWidth: 80,
                frame: true,
                defaults: { width: '85%' },
                bodyStyle: 'padding:50px 0 0 0',
                items: [
                    { xtype: 'numberfield', fieldLabel: '进度', allowBlank: false, name: 'Percent', allowDecimals: false, allowNegative: false },
                    { xtype: 'textarea', name: 'Remark', fieldLabel: '备注' }
                ]
            });
        }
        return this.formpanel;
    }
});
